<template>
  <div>
    <div v-show="!isShowDetail">
      <jxf-titletip :title="title" @refreshPage="refreshPage"></jxf-titletip>
      <el-card class="mt20">
        <el-form :inline="true" :model="searchInfo" ref="searchInfo">
          <el-form-item label="企业名称:" prop="enterpriseName">
            <el-input ref="enterpriseName" v-model="searchInfo.enterpriseName"
                      @keyup.enter.native="$refs['telphone'].focus()" clearable></el-input>
          </el-form-item>
          <el-form-item label="账号:" prop="telphone">
            <el-input ref="telphone" v-model="searchInfo.telphone"
                      @keyup.enter.native="$refs['applyNo'].focus()" clearable></el-input>
          </el-form-item>
          <el-form-item label="订单号:" prop="applyNo">
            <el-input ref="applyNo" v-model="searchInfo.applyNo"
                      @keyup.enter.native="$refs['withdrawStatus'].focus()" clearable></el-input>
          </el-form-item>
          <el-form-item label="处理状态:" prop="withdrawStatus">
            <el-select v-model="searchInfo.withdrawStatus" clearable placeholder="全部">
              <el-option ref="status" v-for="item in withdrawStatusList" :key="item.value" :label="item.label"
                         :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <jxf-Date :startTime.sync="searchInfo.applyStartTime" :endTime.sync="searchInfo.applyEndTime"
                    label="发起时间段："></jxf-Date>
          <el-form-item>
            <el-button type="primary" @click="onSearch()">搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="info" @click="resetForm('searchInfo')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <el-card class="jxf-table-card mt20">
        <div slot="header" class="clearfix">
          <span>数据列表</span>
          <div>
            <el-button type="primary" @click="exportInfo" :loading="exportLoading">导出</el-button>
          </div>
        </div>
        <jxf-table class="" :table="dataTable">
          <template slot="withdrawStatus" slot-scope="scope">
            <span>{{scope.row.withdrawStatus === 1 ? "处理中" : scope.row.withdrawStatus === 2 ? "成功" : scope.row.withdrawStatus === 3 ? "失败" : ""}}</span>
          </template>
          <template slot="operation" slot-scope="scope">
            <el-button type="text" @click="showDetail(scope.row)">查看详情</el-button>
          </template>
        </jxf-table>
      </el-card>
      <jxf-pagination class="mt20" :pageTotal="pageTotal" :currentPage.sync='currentPage' :pageSize.sync="pageSize"
                      @currentPageChange="currentPageChange" @pageSizeChange="pageSizeChange"></jxf-pagination>
    </div>
    <WithdrawCashLaunchDetail ref="WithdrawCashLaunchDetail" v-show="isShowDetail" :isShowDetail.sync="isShowDetail" @getList="getList"></WithdrawCashLaunchDetail>
  </div>
</template>

<script>
  import formatDate from '@/assets/js/formatDate'
  import WithdrawCashLaunchDetail from './components/WithdrawCashLaunchDetail'

  export default {
    name: "WithdrawCashLaunchList",
    components: {WithdrawCashLaunchDetail},
    data() {
      return {
        title: "发起列表管理",
        withdrawStatusList: [{
          label: "处理中",
          value: 1
        }, {
          label: "成功",
          value: 2
        }, {
          label: "失败",
          value: 3
        }],
        searchInfoBack: {
          enterpriseName: "",
          telphone: "",
          applyNo: "",
          withdrawStatus: null,
          applyStartTime: "",
          applyEndTime: ""
        },
        exportLoading: false,
        searchInfo: {
          enterpriseName: "",
          telphone: "",
          applyNo: "",
          withdrawStatus: null,
          applyStartTime: "",
          applyEndTime: ""
        },
        dataTable: {},
        currentPage: 1,
        pageSize: 10,
        pageTotal: 0,
        isShowDetail: false
      }
    },
    methods: {
      init() {
        this.dataTable = {
          border: true,
          loading: true,
          tr: [
            {
              id: '1',
              label: '订单号',
              width: '210',
              prop: 'applyNo'
            },
            {
              id: '2',
              label: '企业名称',
              prop: 'enterpriseName'
            },
            {
              id: '3',
              label: '账号',
              width: '120',
              prop: 'telphone'
            },
            {
              id: '5',
              label: '提现金额',
              minWidth: '120',
              prop: 'amount'
            },
            {
              id: '6',
              label: '手续费',
              minWidth: '120',
              prop: 'chargeAmount'
            },
            {
              id: '7',
              label: '处理状态',
              show: 'template',
              prop: 'withdrawStatus'
            },
            {
              id: '8',
              label: '审核时间',
              width: '160',
              prop: 'auditTime'
            },
            {
              id: '9',
              label: '发起时间',
              width: '160',
              prop: 'applyTime'
            },
            {
              id: '10',
              label: '操作',
              show: 'template',
              minWidth: "100",
              prop: 'operation',
              fixed: "right"
            }
          ],
          data: []
        }
      },
      getList() {
        let info = formatData.clearObjEmptyPrama({...this.searchInfo, pageSize: this.pageSize, pageNum: this.currentPage})
        ajax.post(apis.factory.getWithdrawRecordPassList, info)
          .then(res => {
            if (res.success === true) {
              this.pageTotal = res.data.total
              if (res.data.dataList !== [] && res.data.dataList !== null) {
                this.dataTable.data = this.formatData(res.data.dataList)
              } else {
                this.dataTable.data = []
              }
              this.dataTable.loading = false
            }
          })
      },
      // 列表数据处理
      formatData(list) {
        return list.map(item => {
          return {
            id: item.id,
            applyNo: item.applyNo,
            enterpriseName: item.enterpriseName,
            telphone: item.telphone,
            userType: item.userType,
            amount: item.amount,
            chargeAmount: item.chargeAmount,
            withdrawStatus: item.withdrawStatus,
            applyTime: item.applyTime !== null && item.applyTime !== "" ? formatDate.timeFormat(item.applyTime) : "",
            auditTime: item.auditTime !== null && item.auditTime !== "" ? formatDate.timeFormat(item.auditTime) : ""
          }
        })
      },
      // 查看详情
      showDetail(row) {
        this.isShowDetail = true
        this.$refs.WithdrawCashLaunchDetail.getInfo(row.id)
      },
      // 导出
      exportInfo(){
        this.exportLoading = true;
        let info = formatData.clearObjEmptyPrama({...this.searchInfo, pageSize: this.pageSize, pageNum: this.currentPage})
        ajax.export(apis.factory.exportWithdrawRecordPassList, info)
          .then(res => {
            this.exportLoading = false
          })
      },
      onSearch() {
        this.currentPage = 1
        this.getList()
      },
      // 搜索表单重置
      resetForm(formName) {
        // this.$refs[formName].resetFields();
        this.searchInfo = {...this.searchInfoBack}
      },
      // 切换页面
      currentPageChange(pageNo) {
        this.currentPage = pageNo
        this.getList()
      },
      // 切换页面条数
      pageSizeChange(pageNo) {
        this.pageSize = pageNo
        this.getList()
      },
      // 刷新页面
      refreshPage() {
        this.currentPage = 1
        this.pageSize = 10
        this.searchInfo = {...this.searchInfoBack}
        this.getList()
      }
    },
    created() {
      this.init()
      this.getList()
    }
  }
</script>

<style scoped>

</style>
